<template>
  <div class="my-counter">
    <button type="button" class="btn btn-light" @click="dwFn">-</button>
    <input type="number" class="form-control inp" :value="value" @input="inputFn">
    <button type="button" class="btn btn-light" @click="upFn">+</button>
  </div>
</template>

<script>
export default {
  props:{
    value:{
      type: Number,
      required: true
    },
  },
    data(){
      return {
        num:1
      }
    },
    methods:{
      upFn(){
        this.num = this.value
        this.num ++
      },
      dwFn(){
        if(this.num>1){
          this.num = this.value
          this.num --
        }
      },
      inputFn(event){
        this.num = Number(event.target.value)
      }
    },
    watch:{
      num(newVal){
        this.$emit('numInput', this.num)
      }

    }
}
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn, .inp{
    transform: scale(0.9);
  }
}
</style>